package com.igeekhome.controller.api;

import com.igeekhome.pojo.DDeliveryToDestinationAreaQuotation;
import com.igeekhome.pojo.DSpecificQuotationSheet;
import com.igeekhome.service.IQuoteDtoService;
import com.igeekhome.util.ResultBean;
import com.igeekhome.util.TableResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 报价维护
 * @author Romeo
 */
@RestController
@RequestMapping("/api/quote")
public class QuoteDtoControllerApi {

    @Autowired
    private IQuoteDtoService quoteDtoService;

    @Value("${SHIPMENT_TYPE}")
    private String SHIPMENT_TYPE;

    @Value("${PRODUCT_TYPE}")
    private String PRODUCT_TYPE;

    @RequestMapping("/list")
    public TableResultBean list(DDeliveryToDestinationAreaQuotation dDeliveryToDestinationAreaQuotation, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){
        return quoteDtoService.selectList(dDeliveryToDestinationAreaQuotation,page,limit);
    }
    @RequestMapping("/handle")
    public ResultBean handle(DDeliveryToDestinationAreaQuotation dDeliveryToDestinationAreaQuotation){
        Integer id = dDeliveryToDestinationAreaQuotation.getOfferId();
        if(id != null) {
          return quoteDtoService.edit(dDeliveryToDestinationAreaQuotation);
        }

        return quoteDtoService.add(dDeliveryToDestinationAreaQuotation);
    }
    @RequestMapping("/delete")
    public ResultBean delete(String idsStr){
        return quoteDtoService.delete(idsStr);
    }

    /**
     * 查看报价信息
     */
    @RequestMapping("/rule/list/{offerId}")
    public TableResultBean ruleList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit,@PathVariable("offerId") Integer offerId) {
        return quoteDtoService.ruleList(page,limit,PRODUCT_TYPE,SHIPMENT_TYPE,offerId.toString());
    }

    @RequestMapping("/checkDelete/{serialId}")
    public ResultBean ruleDelete(@PathVariable("serialId") Integer serialId){
        return quoteDtoService.ruleDelete(serialId);

    }

    @RequestMapping("/rule/handle")
    public ResultBean ruleHandle(DSpecificQuotationSheet dSpecificQuotationSheet){
        System.out.println("dSpecificQuotationSheet==="+dSpecificQuotationSheet);
        if(dSpecificQuotationSheet.getSerialId() == null) {
            // 新增
            return quoteDtoService.ruleAdd(dSpecificQuotationSheet);
        } else {
            // 更新
            return quoteDtoService.ruleEdit(dSpecificQuotationSheet);
        }
    }



}
